Unit urmarapor1;

Interface

Uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, fcStatusBar, ExtCtrls, Grids, Wwdbigrd, Wwdbgrid,
  wwdbdatetimepicker, wwdbedit, wwdblook, StdCtrls, Mask, Wwdotdot,
  Wwdbcomb, ppDB, ppDBPipe, ppComm, ppRelatv, ppProd, ppClass, ppReport,
  ppCtrls, ppVar, ppPrnabl, ppBands, ppCache, ppParameter;

Type
  Tfrmaraporu = Class(TForm)
    liste: TADOQuery;
    Panel1: TPanel;
    fcStatusBar1: TfcStatusBar;
    Panel3: TPanel;
    wwDBGrid1: TwwDBGrid;
    DataSource1: TDataSource;
    Panel2: TPanel;
    Label14: TLabel;
    Label15: TLabel;
    Bevel1: TBevel;
    Label56546: TLabel;
    Label2: TLabel;
    durumu: TwwDBComboBox;
    CheckBox1: TCheckBox;
    FirmaAdi: TwwDBEdit;
    basTar: TwwDBDateTimePicker;
    BitTar: TwwDBDateTimePicker;
    CikDepo: TwwDBComboBox;
    wwDBEdit1: TwwDBEdit;
    CheckBox3: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Memo1: TMemo;
    report: TppReport;
    ppDBPipeline1: TppDBPipeline;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppTitleBand1: TppTitleBand;
    ppLabel1: TppLabel;
    ppSystemVariable1: TppSystemVariable;
    ppSystemVariable2: TppSystemVariable;
    ppDBText1: TppDBText;
    ppLabel2: TppLabel;
    ppDBText3: TppDBText;
    ppLabel4: TppLabel;
    ppDBText4: TppDBText;
    ppLabel5: TppLabel;
    ppDBText5: TppDBText;
    ppLabel6: TppLabel;
    ppDBText6: TppDBText;
    ppLabel7: TppLabel;
    ppDBText7: TppDBText;
    ppLabel8: TppLabel;
    ppDBText8: TppDBText;
    ppLabel9: TppLabel;
    ppLine2: TppLine;
    ppLabel3: TppLabel;
    ppDBText2: TppDBText;
    ppShape1: TppShape;
    ppShape2: TppShape;
    ppLine3: TppLine;
    ppLine4: TppLine;
    ppLine5: TppLine;
    ppLine6: TppLine;
    ppLine7: TppLine;
    ppLine8: TppLine;
    ppLine9: TppLine;
    ppLine10: TppLine;
    ppLine12: TppLine;
    ppLine13: TppLine;
    ppLine14: TppLine;
    ppLine15: TppLine;
    ppLine16: TppLine;
    ppLine17: TppLine;
    ppLabel10: TppLabel;
    ppLabel11: TppLabel;
    ppLabel12: TppLabel;
    ppShape3: TppShape;
    ppShape5: TppShape;
    ppShape6: TppShape;
    ppShape7: TppShape;
    ppLabel13: TppLabel;
    ppLabel14: TppLabel;
    ppSystemVariable3: TppSystemVariable;
    Procedure FormCreate(Sender: TObject);
    Procedure cariara(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
    Procedure CikDepoCloseUp(Sender: TwwDBComboBox; Select: Boolean);
    Procedure sonraki(Sender: TObject; Var Key: Char);
    Procedure CheckBox3Click(Sender: TObject);
    Procedure CheckBox5Click(Sender: TObject);
    Procedure CheckBox6Click(Sender: TObject);
    Procedure CheckBox1Click(Sender: TObject);
    Procedure stokkodubul(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
    Procedure Button1Click(Sender: TObject);
    Procedure Button2Click(Sender: TObject);
    Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
    Procedure wwDBGrid1CalcTitleImage(Sender: TObject; Field: TField;
      Var TitleImageAttributes: TwwTitleImageAttributes);
    Procedure wwDBGrid1TitleButtonClick(Sender: TObject;
      AFieldName: String);
    Procedure Button3Click(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
    sira: String[25];
    bk: String[10];
  End;

Var
  frmaraporu: Tfrmaraporu;
  stokkod, carikod: integer;

Implementation

Uses data, cariaral, ucariara2, stokaral, Unit2;

{$R *.dfm}

Procedure Tfrmaraporu.FormCreate(Sender: TObject);
Begin
  If dm.connect.Connected Then
  Begin
    dm.spdepo.Parameters.parambyname('@depokod').Value := 0;
    dm.spdepo.Open;
    dm.spdepo.First;
    CikDepo.Items.Clear;
    While (Not dm.spdepo.Eof) Do
    Begin
      CikDepo.Items.Add(dm.spdepo.FieldByName('firmaadi').asstring + #9 +
        dm.spdepo.FieldByName('carikod').asstring);
      dm.spdepo.Next;
    End;
    CikDepo.ApplyList;

    carikod := 0;
  End;
End;

Procedure Tfrmaraporu.cariara(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Var
  t: integer;
Begin
  t := TwwDBEdit(sender).Tag;
  If (key = 13) And ((sender As TwwDBEdit).text <> '') Then
  Begin
    dm.Cariara.Close;
    dm.Cariara.SQL.Clear;
    dm.Cariara.SQL.Add('select distinct carikod,KARGOKOD, carikodu, istihbarat,Tekyetkili, CTipi=(select adi from dbo.carituru where id=Tipi), FirmaAdi, Soyadi, ilce, Sehir,telefon3,KARGOADI=(select top 1 Ad from tbl_KargoTanim where ID=KARGOKOD) from Cari');

    dm.Cariara.SQL.Add('where (CariKod>0)');
    If t = 1 Then
      dm.Cariara.SQL.Add('and (carikodu like ''' + TEdit(sender).text +
        '%'' )');
    If t = 2 Then
      dm.Cariara.SQL.Add('and (FirmaAdi like ''' + TEdit(sender).text +
        '%'' )');
    dm.Cariara.Open;
    If (dm.CariAra.RecordCount = 1) Then
    Begin
      cariKod := dm.cariara.FieldByName('carikod').value;
      //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
      FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
    End
    Else
    Begin
      If (dm.cariAra.RecordCount > 1) Then
      Begin
        If Not assigned(fCariaraL) Then
          fCariAraL := tfCariAral.create(self);
        If t = 1 Then
        Begin
          fCariAraL.siras := 'carikodu';
          fCariAraL.aranan := TEdit(sender).text;
        End;
        If t = 2 Then
        Begin
          fCariAraL.siras := 'FirmaAdi';
          fCariAraL.aranan := TEdit(sender).text;
        End;

        If fCariAraL.showmodal = mrOk Then
        Begin
          cariKod := dm.cariara.FieldByName('carikod').value;
          //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
          FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
        End
        Else
        Begin
          fCariAra2 := tfCariAra2.create(self);
          If t = 1 Then
            fCariAra2.edit3.Text := TEdit(sender).text;
          If t = 2 Then
            fCariAra2.edit4.Text := TEdit(sender).text;
          If fCariAra2.showmodal = mrok Then
          Begin
            If dm.CariAra.Active = true Then
            Begin
              cariKod := dm.cariara.FieldByName('carikod').value;
              //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
              FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
            End;
          End;
        End;
      End
      Else
      Begin
        fCariAra2 := tfCariAra2.create(self);
        If t = 1 Then
          fCariAra2.edit3.Text := TEdit(sender).text;
        If t = 2 Then
          fCariAra2.edit4.Text := TEdit(sender).text;
        fCariAra2.gelis := t;
        If fCariAra2.showmodal = mrok Then
        Begin
          If dm.CariAra.Active = true Then
          Begin
            cariKod := dm.cariara.FieldByName('carikod').value;
            //     carikodu.text:=dm.cariara.FieldByName('CariKodu').asstring;
            FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
          End;
        End;
      End;
    End;
  End;

End;

Procedure Tfrmaraporu.CikDepoCloseUp(Sender: TwwDBComboBox;
  Select: Boolean);
Begin
  If select Then
  Begin
    FirmaAdi.Text := '';
  End;
End;

Procedure Tfrmaraporu.sonraki(Sender: TObject; Var Key: Char);
Begin
  If key = #13 Then
  Begin
    Key := #0;
    Perform(CM_DialogKey, VK_TAB, 0);
  End;

End;

Procedure Tfrmaraporu.CheckBox3Click(Sender: TObject);
Begin
  If CheckBox3.Checked Then
  Begin
    FirmaAdi.Enabled := True;
    FirmaAdi.text := '';
    carikod := 0;
    If CheckBox5.Checked Then
      CheckBox5.Checked := false;
    firmaadi.SetFocus;
  End
  Else
  Begin
    FirmaAdi.Enabled := False;
    firmaadi.Text := '';
  End;

End;

Procedure Tfrmaraporu.CheckBox5Click(Sender: TObject);
Begin
  If CheckBox5.Checked Then
  Begin
    CikDepo.Enabled := true;
    CikDepo.ItemIndex := 0;
    CikDepo.SetFocus;
    If CheckBox3.Checked Then
      CheckBox3.Checked := false;
  End
  Else
  Begin
    CikDepo.ItemIndex := -1;
    CikDepo.Enabled := False;
  End;

End;

Procedure Tfrmaraporu.CheckBox6Click(Sender: TObject);
Begin
  If CheckBox6.Checked Then
  Begin
    wwDBEdit1.Enabled := true;
    wwdbedit1.setfocus;
  End
  Else
  Begin
    wwDBEdit1.Enabled := False;
    wwDBEdit1.Text := '';
  End;

End;

Procedure Tfrmaraporu.CheckBox1Click(Sender: TObject);
Begin
  If CheckBox1.Checked Then
  Begin
    durumu.Enabled := true;
    durumu.ItemIndex := 0;
    durumu.setfocus;
  End
  Else
  Begin
    durumu.ItemIndex := -1;
    durumu.Enabled := False;
  End;

End;

Procedure Tfrmaraporu.stokkodubul(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Var
  t: integer;
Begin
  t := TEdit(sender).Tag;
  If (key = 13) And (TEdit(sender).text <> '') Then
  Begin
    dm.stokara.Close;
    dm.stokara.SQL.Clear;
    dm.stokara.SQL.Add(dm.StokilkSql);
    dm.stokara.SQL.Add('where (stok.stokkod>0) ');
    If t = 1 Then
      dm.stokara.SQL.Add('and stokkodu like ''' + TEdit(sender).text + '%''');
    If t = 2 Then
      dm.stokara.SQL.Add('and cinsi like ''' + TEdit(sender).text + '%''');
    dm.stokara.Open;

    If (dm.stokara.RecordCount = 1) Then
    Begin
      stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
      wwDBEdit1.text := dm.stokara.Fieldbyname('Cinsi').asString;
    End
    Else
    Begin
      If (dm.stokara.RecordCount > 1) Then
      Begin
        If Not assigned(fStokaral) Then
          fStokaral := tfStokaral.create(self);

        If fstokaral.showmodal = mrOk Then
        Begin
          stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
          wwDBEdit1.text := dm.stokara.Fieldbyname('Cinsi').asString;
        End
        Else
        Begin
          fstokara2 := tfstokara2.create(self);
          If t = 1 Then
            fstokara2.edit3.Text := TEdit(sender).text;
          If t = 2 Then
            fstokara2.edit4.Text := TEdit(sender).text;
          If fstokara2.showmodal = mrok Then
          Begin
            If dm.stokara.Active = true Then
            Begin
              stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
              wwDBEdit1.text := dm.stokara.Fieldbyname('Cinsi').asString;
            End;
          End;
        End;
      End
      Else
      Begin
        fstokara2 := tfstokara2.create(self);
        If t = 1 Then
          fstokara2.edit3.Text := TEdit(sender).text;
        If t = 2 Then
          fstokara2.edit4.Text := TEdit(sender).text;
        fstokara2.gelis := t;
        If fstokara2.showmodal = mrok Then
        Begin
          If dm.stokara.Active = true Then
          Begin
            stokkod := dm.stokara.Fieldbyname('stokkod').asInteger;
            wwDBEdit1.text := dm.stokara.Fieldbyname('Cinsi').asString;
          End;
        End;
      End;
    End;
  End;

End;

Procedure Tfrmaraporu.Button1Click(Sender: TObject);
Begin
  liste.close;
  liste.sql.clear;
  liste.SQL.Add('select partnumber='''', s.stokkodu , s.cinsi , s.modelname ,                                                    ');
  liste.SQL.Add('country = (select distinct ulke from cari c , fatura f where  c.carikod=f.carikod and f.bilisno=h.bilisnogir)');
  liste.SQL.Add(', p.serino ,h.verilengaranti , t.bildirilenariza                                                                ');
  liste.SQL.Add('from pardeg p , fatharhar h , stok s , teknik t                                                                 ');
  liste.SQL.Add('where (p.serino = h.serinos) and (s.stokkod = h.stokkod) and (t.serino=h.serinos)                               ');

  If (trim(basTar.Text) <> '') And (trim(BitTar.Text) <> '') Then
    liste.SQL.Add('and (p.tarih>:bastar) and (p.tarih<:bittar)');

  //if (carikod>0) and CheckBox3.Checked then   liste.SQL.Add('and (CarikodGir='+inttostr(carikod)+')');
//  if CheckBox1.Checked then   liste.SQL.Add('and (Durumu='''+durumu.value+''')');
//  if CheckBox2.Checked then   liste.SQL.Add('and (teknik.Tipi='''+Tipi.LookupValue+''')');
//  if CheckBox4.Checked then   liste.SQL.Add('and (teknik.cikisi='''+cikis.Value+''')');
  If CheckBox5.Checked Then
    liste.SQL.Add('and (p.cikdepokod=''' + CikDepo.value + ''')');

  If (stokkod > 0) And CheckBox6.Checked Then
    liste.SQL.Add('and (h.stokkod=' + inttostr(stokkod) + ')');

  Memo1.Text := liste.SQL.Text;
  If (trim(basTar.Text) <> '') And (trim(BitTar.Text) <> '') Then
  Begin
    liste.Parameters.ParamByName('bastar').value := BasTar.date;
    liste.Parameters.ParamByName('bittar').value := BitTar.date + 1;
  End;

  liste.open;

End;

Procedure Tfrmaraporu.Button2Click(Sender: TObject);
Begin
  close;
End;

Procedure Tfrmaraporu.FormClose(Sender: TObject; Var Action: TCloseAction);
Begin
  Action := cafree;
  frmaraporu := Nil;
End;

Procedure Tfrmaraporu.wwDBGrid1CalcTitleImage(Sender: TObject;
  Field: TField; Var TitleImageAttributes: TwwTitleImageAttributes);
Begin
  If field.FieldName = sira Then
  Begin
    If bk = ' ASC' Then
      TitleImageAttributes.imageIndex := 0
    Else
      TitleImageAttributes.imageIndex := 1;
  End
  Else
    TitleImageAttributes.imageIndex := -1;

End;

Procedure Tfrmaraporu.wwDBGrid1TitleButtonClick(Sender: TObject;
  AFieldName: String);
Begin
  If AFieldName = sira Then
  Begin
    If bk = ' ASC' Then
      bk := ' DESC'
    Else
      bk := ' ASC';
  End
  Else
    bk := ' ASC';
  sira := AFieldName;
  liste.Sort := sira + bk;
  wwDBGrid1.RedrawGrid;
End;

Procedure Tfrmaraporu.Button3Click(Sender: TObject);
Begin
  liste.DisableControls;
  If liste.RecordCount > 0 Then
    report.Print;
  liste.EnableControls;
End;

End.
